#---
# Excerpted from "Rails for PHP Developers",
# published by The Pragmatic Bookshelf.
# Copyrights apply to this code. It may not be used to create training material, 
# courses, books, articles, and the like. Contact us if you are in doubt.
# We make no guarantees that this code is fit for any purpose. 
# Visit http://www.pragmaticprogrammer.com/titles/ndphpr for more book information.
#---
class SessionsController < ApplicationController
  
  def new
  end

  def create
    @current_user = User.authenticate(params[:email], params[:password]) 
    if @current_user
      session[:user]  = @current_user.id
      redirect_to :controller => "users", :action => "show", 
                  :id => @current_user.id
    else
      flash[:notice] = "No user was found with this email/password"
      render :action => 'new'
    end
  end
  

  
  def destroy
    reset_session

    flash[:notice] = "Logged out successfully"
    redirect_to :action => "new"
  end
  
end
